using System;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
using System.IO;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Net;
using System.Text;
using System.Threading;

namespace CStock
{
    
    public class Bundesbank : DatafeedHandler
    {

        #region private members

        protected List<IDataItem> ValidationQueue;
        protected List<IDataItem> DatafeedQueue;
        
        
        //private bool bOnly200;
        
        protected IPortfolio portfolio;

        
        protected string url_publicYieldGermany;
        protected string url_inflationGermany;
        protected string url_treasury1Year;
        protected string url_treasury10Years;
        protected string url_euribor3Month;
        protected string url_bankLendings1To2Years;
        protected string url_ecb;
        protected string url_gold;

        
        protected string url_unemploymentRate;
        protected string url_euro_Yen;
        protected string url_Euro_USD;
        protected string url_Euro_GBP;
        protected string url_German_BIP;
        protected string url_Industry_Orders;
        protected string url_Industry_trades;
        protected string url_ECB_M3;
        protected string url_ECB_M1_M2_M3_Cash;

        protected string url_ECB_Gold_Valuta;
        protected string url_ECB_cash_Flow;
        protected bool bundesbank;

        protected string url_Federal_fundsEffective;
        protected string url_Federal_fundsEffective_monthly;
        protected string url_Federal_corporateBonds_monthly;
        protected string url_Federal_interestRateSwaps_daily;

        protected string url_Federal_treasury10years_daily;
        protected string url_Federal_BankPrimeLoan_daily;

        #endregion

        #region construct

        public Bundesbank():base()
        {
            
            ValidationQueue = new List<IDataItem>();
            DatafeedQueue = new List<IDataItem>();

            this.url_publicYieldGermany = @"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_wt0017&csvformat=de&euro=mixed&tr=WT0017";
            this.url_inflationGermany = @"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_YSD42S&csvformat=de&euro=mixed&tr=YSD42S";
            this.url_treasury1Year = @"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_WZ9808&csvformat=de&euro=mixed&tr=WZ9808";
            this.url_treasury10Years = @"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_WT3229&csvformat=de&euro=mixed&tr=WT3229";

            this.url_euribor3Month = @"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_ST0325&csvformat=de&euro=mixed&tr=ST0325";
            this.url_bankLendings1To2Years = @"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_WT0905&csvformat=de&euro=mixed&tr=WT0905";
            this.url_ecb = @"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_SU0202&csvformat=de&euro=mixed&tr=SU0202";
            this.url_gold = @"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_WT5503&csvformat=de&euro=mixed&tr=WT5503";

            this.url_unemploymentRate = @"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_UUCC02&csvformat=de&euro=mixed&tr=UUCC02";
            this.url_euro_Yen = @"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_WT5630&csvformat=de&euro=mixed&tr=WT5630";
            this.url_Euro_USD = @"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_WT5636&csvformat=de&euro=mixed&tr=WT5636";
            this.url_Euro_GBP = @"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_WT5627&csvformat=de&euro=mixed&tr=WT5627";
            this.url_German_BIP = @"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_JQB000&csvformat=de&euro=mixed&tr=JQB000";
            this.url_Industry_Orders = @"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_USA002&csvformat=de&euro=mixed&tr=USA002";
            this.url_Industry_trades = @"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_US366A&csvformat=de&euro=mixed&tr=US366A";
            this.url_ECB_M3 = @"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_TVE303&csvformat=de&euro=mixed&tr=TVE303";
            this.url_ECB_M1_M2_M3_Cash = @"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_TVE300&csvformat=de&euro=mixed&tr=TVE300";

            this.url_ECB_Gold_Valuta = @"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_AU1714&csvformat=de&euro=mixed&tr=AU1714";
            this.url_ECB_cash_Flow = @"http://www.bundesbank.de/statistik/statistik_zeitreihen_download.php?func=directcsv&from=&until=&filename=bbk_AU1720&csvformat=de&euro=mixed&tr=AU1720";

            url_Federal_fundsEffective = @"https://www.federalreserve.gov/releases/h15/data/Daily/H15_FF_O.txt";
            this.url_Federal_fundsEffective_monthly = @"https://www.federalreserve.gov/releases/h15/data/Monthly/H15_FF_O.txt";
            this.url_Federal_corporateBonds_monthly = @"https://www.federalreserve.gov/releases/h15/data/Monthly/H15_AAA_NA.txt";

            this.url_Federal_interestRateSwaps_daily = @"https://www.federalreserve.gov/releases/h15/data/Business_day/H15_SWAPS_Y1.txt";
            this.url_Federal_treasury10years_daily = @"https://www.federalreserve.gov/releases/h15/data/Business_day/H15_TCMNOM_Y10.txt";

            this.url_Federal_BankPrimeLoan_daily = @"https://www.federalreserve.gov/releases/h15/data/Daily/H15_PRIME_NA.txt";



            //further pages
            //yahoo real time : http://finance.yahoo.com/q/ecn?s=MSFT
            //http://www.webservicex.net/RealTimeMarketData.asmx
            //http://www.webservicex.net/RealTimeMarketData.asmx?Disco
            //http://www.webservicex.net/RealTimeMarketData.asmx?wsdl

        }

        #endregion

        #region unused

        //public virtual void RequestValidation(IDataItem Entity)
        //{
        //    AddEntityToValidationQueue(Entity);
        //}


        //[MethodImpl(MethodImplOptions.Synchronized)]
        //private void AddEntityToValidationQueue(IDataItem Entity)
        //{
        //    ValidationQueue.Add(Entity);
        //}

        //[MethodImpl(MethodImplOptions.Synchronized)]
        //private void AddEntityToDatafeedQueue(IDataItem Entity)
        //{
        //    DatafeedQueue.Add(Entity);
        //}
        //[MethodImpl(MethodImplOptions.Synchronized)]
        //public virtual void SubscribeDatafeed(IDataItem Entity)
        //{
        //    AddEntityToDatafeedQueue(Entity);
        //}
        //[MethodImpl(MethodImplOptions.Synchronized)]
        //private IDataItem GetEntityFromValidationQueue()
        //{
        //    IDataItem ReturnObj = null;

        //    if (ValidationQueue.Count > 0)
        //    {
        //        //System.Exception ex = new Exception("Error");
        //        throw new System.Exception("Error");

        //        //ReturnObj = (ValidationQueue.RemoveAt(0));
        //    }
        //    return ReturnObj;
        //}

        //[MethodImpl(MethodImplOptions.Synchronized)]
        //private IDataItem GetEntityFromDatafeedQueue()
        //{
        //    IDataItem ReturnObj = null;

        //    if (DatafeedQueue.Count > 0)
        //    {
        //        ReturnObj = DatafeedQueue[0];
        //    }
        //    return ReturnObj;
        //}

        #endregion

        #region properties

        public IPortfolio Portfolio
        {
            get
            {
                return this.portfolio;
            }
            set
            {
                portfolio = value;
            }
        }

        #endregion

        #region helpers

        protected string ReadPage_ToString(string myURL)
        {

            System.IO.Stream stream = webclient.OpenRead(myURL);
            StreamReader sr = new StreamReader(stream);
            string pageContent = sr.ReadToEnd();
            return pageContent;

        }
        private double CalculateQuoteDifference(ListQuotes quotes, IQuote q, TimeSpan timeToSubtract)
        {
            DateTime newDate = q.DATE.Subtract(timeToSubtract);
            IQuote qOld = quotes[newDate] as IQuote;
            TimeSpan ts = q.DATE - qOld.DATE;
            double percent = 0f;
            percent = (q.CLOSEc - qOld.CLOSEc) * 100f / qOld.CLOSEc;
            double factor = 1f;
            if (ts.Days > 0)
                factor = 365f / ts.Days;

            percent = factor * (q.CLOSEc - qOld.CLOSEc) * 100f / qOld.CLOSEc;

            return percent;
        }

        private bool Read_Internet_Page_List(StringCollection strCollection, bool bundesbank)
        {
            //object o = null;
            ListQuotes qc = new ListQuotes(dataItem.DataClass);
            int istart = 5;
            if (!bundesbank)
                istart = 10;
            for (int iLines = istart; iLines < strCollection.Count; iLines++)
            {
                string strLine = strCollection[iLines];
                if (bundesbank)
                    ReadBundesbankLine(strLine, qc);
                else
                {
                    ReadFEDLine(strLine, qc);
                }


            }
            if (qc[qc.Count - 1].DATE < DateTime.Now)
            {
                IQuote qu = qc[qc.Count - 1].Clone() as IQuote;
                qu.DATE = DateTime.Now;

                qc.Add(qu);
            }

            dataItem.DataClass.QuoteCollection = qc;
            dataItem.DataClass.Serialize();
            return true;

        }

        #endregion

        #region implementation


        public bool TestConnect()
        {
            bool State = false;

            try
            {
                string myURL = "http://finance.yahoo.com";
                string pageContent = ReadPage_ToString(myURL);



                if (pageContent.Length > 40)
                {
                    State = true;
                }
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("Error downloading");
            }

            //SetConnected(State);

            return State;
        }

     
        public bool DoValidation(IDataItem mydataItem)
        {
            this.dataItem = mydataItem;
            bool validated = false;
            try
            {
                //----------------------------



                string myURL = "http://finance.yahoo.com:80/d/quotes.csv?s=" + dataItem.Symbol + "&f=sl1d1t1c1ohgv&e=.csv";
                string pageContent = ReadPage_ToString(myURL);


                string[] list2 = pageContent.Split(new Char[] { ',' });
                list2[0] = list2[0].Replace("\"", "");
                list2[2] = list2[2].Replace("\"", "");

                string mySymbol = list2[0].ToUpper();
                string myDate = list2[2].ToUpper();

                if (mySymbol == dataItem.Symbol)
                {
                    if (myDate != "N/A")
                    {
                        validated = true;
                    }

                }


            }
            catch
            {
                validated = false;
            }
            return validated;

        }
        private void DownloadComplete_YahooSeries_1(byte[] dataDownloaded)
        {

            string strPage = dataDownloaded.ToString();


        }
        protected bool CheckPresenceOfQuote(string strLine)
        {
            if (strLine != null && strLine != string.Empty)
            {
                string[] list = strLine.Split(new Char[] { ',' });
                string myDate = list[0].ToUpper();
                string myOpen = list[1].ToUpper();
                string myHigh = list[2].ToUpper();
                string myLow = list[3].ToUpper();
                string myClose = list[4].ToUpper();
                if (myDate == "DATE" && myOpen == "OPEN" && myHigh == "HIGH" && myLow == "LOW" && myClose == "CLOSE")
                {
                    return true;
                }


            }


            return false;


        }

     
        public bool GetTimeSeries_Special(IDataItem mydataItem, DateTime myDateStart, bool inThread, bool isbundesbank)
        {

            this.dataItem = mydataItem;
            this.dateStart = myDateStart;
            this.bundesbank = isbundesbank;
            if (inThread)
            {
                Thread updateThread = new Thread(new ThreadStart(GetTimeSeries_Special_Thread));
                updateThread.Start();
            }
            else
            {
                GetTimeSeries_Special_Thread();
            }
            return true;


        }



        private string SetURL_FED()
        {
            string myURL = string.Empty;
            switch (dataItem.WebStockType)
            {
                case CStock.Web.WebStockType.FED_funds_rate_effective:
                    {
                        myURL = this.url_Federal_fundsEffective;
                        break;

                    }
                     case CStock.Web.WebStockType.FED_funds_rate_effective_monthly:
                    {
                        myURL = this.url_Federal_fundsEffective_monthly;
                        break;

                    }
                     case CStock.Web.WebStockType.FED_corporateBonds_monthly:
                    {
                        myURL = this.url_Federal_corporateBonds_monthly;
                        break;

                    }
                     case CStock.Web.WebStockType.FED_interestRateSwaps_daily:
                    {
                        myURL = this.url_Federal_interestRateSwaps_daily;
                        break;

                    }
                     case CStock.Web.WebStockType.FED_treasury10years_daily:
                    {
                        myURL = this.url_Federal_treasury10years_daily;
                        break;

                    }
                     case CStock.Web.WebStockType.FED_BankPrimeLoan_daily:
                    {
                        myURL = this.url_Federal_BankPrimeLoan_daily;
                        break;

                    }
               
        

                    
            }
            return myURL;
        }
        private string SetURL_Bundesbank()
        {
            string myURL = string.Empty;
            switch (dataItem.WebStockType)
            {
                case CStock.Web.WebStockType.Bundesbank_PublicYield:
                    {
                        myURL = this.url_publicYieldGermany;
                        break;

                    }
                case CStock.Web.WebStockType.Bundesbank_Inflation:
                    {
                        myURL = this.url_inflationGermany;
                        break;

                    }
                case CStock.Web.WebStockType.Bundesbank_Inflation_OneMonth:
                    {
                        myURL = this.url_inflationGermany;
                        break;

                    }

                case CStock.Web.WebStockType.Bundesbank_PriceIndex:
                    {
                        myURL = this.url_inflationGermany;
                        break;

                    }
                case CStock.Web.WebStockType.BB_bankLendings1To2Years:
                    {
                        myURL = this.url_bankLendings1To2Years;
                        break;

                    }
                case CStock.Web.WebStockType.BB_ecb_effectiveRateMonthly:
                    {
                        myURL = this.url_ecb;
                        break;

                    }
                case CStock.Web.WebStockType.BB_euribor3Month:
                    {
                        myURL = this.url_euribor3Month;
                        break;

                    }
                case CStock.Web.WebStockType.BB_Euro_GBP:
                    {
                        myURL = this.url_Euro_GBP;
                        break;

                    }
                case CStock.Web.WebStockType.BB_Euro_USD:
                    {
                        myURL = this.url_Euro_USD;
                        break;

                    }
                case CStock.Web.WebStockType.BB_euro_Yen:
                    {
                        myURL = this.url_euro_Yen;
                        break;

                    }
                case CStock.Web.WebStockType.BB_German_BIP:
                    {
                        myURL = this.url_German_BIP;
                        break;

                    }
                case CStock.Web.WebStockType.BB_gold:
                    {
                        myURL = this.url_gold;
                        break;

                    }
                case CStock.Web.WebStockType.BB_Industry_Orders:
                    {
                        myURL = this.url_Industry_Orders;
                        break;

                    }
                case CStock.Web.WebStockType.BB_Industry_trades:
                    {
                        myURL = this.url_Industry_trades;
                        break;

                    }
                case CStock.Web.WebStockType.BB_unemploymentRate:
                    {
                        myURL = this.url_unemploymentRate;
                        break;

                    }
                case CStock.Web.WebStockType.ECB_cash_Flow:
                    {
                        myURL = this.url_ECB_cash_Flow;
                        break;

                    }
                case CStock.Web.WebStockType.ECB_Gold_Valuta:
                    {
                        myURL = this.url_ECB_Gold_Valuta;
                        break;

                    }
                case CStock.Web.WebStockType.ECB_M1_M2_M3_Cash:
                    {
                        myURL = this.url_ECB_M1_M2_M3_Cash;
                        break;

                    }
                case CStock.Web.WebStockType.ECB_M3:
                    {
                        myURL = this.url_ECB_M3;
                        break;

                    }
                case CStock.Web.WebStockType.treasury1Year:
                    {
                        myURL = this.url_treasury1Year;
                        break;

                    }
                case CStock.Web.WebStockType.treasury10Years:
                    {
                        myURL = this.url_treasury10Years;
                        break;

                    }



            }
            return myURL;
        }
     
        private void AdaptInflation_PerPeriod(int iTime)
        {
            int intervalForInflation = 365;
            if (iTime < 365)
            {
                intervalForInflation = 29;
            }
            ListQuotes quotes = dataItem.DataClass.QuoteCollection as ListQuotes;
            //int intervalForInflation = 365;

            TimeSpan inflationTimeSpan = new TimeSpan(intervalForInflation, 0, 0, 0);
            TimeSpan oneMonth = new TimeSpan(intervalForInflation, 0, 0, 0);
            TimeSpan twoMonth = new TimeSpan(59, 0, 0, 0);
            TimeSpan threeMonth = new TimeSpan(89, 0, 0, 0);


            IQuote qFirst = quotes[0];
            for (int i = quotes.Count - 1; i >= 0; i--)
            {
                IQuote q = quotes[i];


                if (iTime == 365)
                {
                    double percentOneYear = CalculateQuoteDifference(quotes, q, inflationTimeSpan);

                    //quotes[i].CLOSEc = (percentOneMonth + percentTwoMonth + percentThreeMonth + percentOneYear) / 4;
                    quotes[i].CLOSEc = percentOneYear;
                }
                else
                {
                    double percentOneYear = CalculateQuoteDifference(quotes, q, inflationTimeSpan);
                    double percentOneMonth = CalculateQuoteDifference(quotes, q, oneMonth);
                    double percentTwoMonth = CalculateQuoteDifference(quotes, q, twoMonth);
                    double percentThreeMonth = CalculateQuoteDifference(quotes, q, threeMonth);

                    quotes[i].CLOSEc = (percentOneMonth + percentTwoMonth + percentThreeMonth + percentOneYear) / 4;
                    //quotes[i].CLOSEc = percentOneYear;
                }

            }
        }
        private void AdaptQuotes_Inflation()
        {

            if (dataItem.WebStockType == CStock.Web.WebStockType.Bundesbank_Inflation)
            {
                AdaptInflation_PerPeriod(365);
            }
            if (dataItem.WebStockType == CStock.Web.WebStockType.Bundesbank_Inflation_OneMonth)
            {
                AdaptInflation_PerPeriod(30);
            }

            //dataItem.DataClass.QuoteCollection = quotes;
            dataItem.DataClass.Serialize();
        }
       
        private void GetTimeSeries_Special_Thread()
        {

            
            if (webClientBusy)
            {
                System.Threading.Thread.Sleep(50);
                GetTimeSeries_Special_Thread();
            }
            else
            {

                this.RaiseObjectChangedEvent(this, "Download init for: " + dataItem.ID, this.dataItem, this.dataItem);
                string myURL = string.Empty;
                if (this.bundesbank)
                {
                     myURL = SetURL_Bundesbank();
                }
                else
                {
                    myURL = SetURL_FED();
                }
               


                //string myURL = this.url_inflationGermany;

                StringCollection strCollection = ReadPage_ToStringCollection(myURL);
                if (strCollection == null || strCollection.Count == 0)
                    return;

                Read_Internet_Page_List(strCollection, this.bundesbank);
                if(this.bundesbank)
                    AdaptQuotes_Inflation();
                this.RaiseObjectChangedEvent(this, "Finished download:" + dataItem.ID, this.dataItem, this.dataItem);


            }
        }
        private bool SetQuoteFromGermanPublicYield(string str, IQuote qu)
        {

            if (str != null && str != string.Empty)
            {
                string str1 = str.Substring(0);
                if (str1 != ".")
                {
                    try
                    {
                        qu.CLOSEc = Convert.ToDouble(str, CUtil.Conversions.CultureGerman);
                        return true;
                    }
                    catch
                    {
                        Debug.WriteLine("Conversion error for quote: " + str);
                        return false;
                    }
                }
            }
            return false;
        }
        private void ReadFEDLine(string strLine, ListQuotes qc)
        {
            if (strLine != null && strLine != string.Empty)
            {
                IQuote qu = new Quote();
                string[] listQuotes = strLine.Split(new Char[] { ',' });
                try
                {
                    qu.DATE = Convert.ToDateTime(listQuotes[0], CUtil.Conversions.CultureAmerican);
                    string str = listQuotes[1];
                    try
                    {
                        qu.CLOSEc = Convert.ToDouble(str, CUtil.Conversions.CultureAmerican);
                        if (qu.DATE > dateStart)
                        {
                            qc.Add(qu);

                        }
                    }
                    catch
                    {
                    }
                   
                }
                catch
                {
                    // do nothing - probably conversion error - at the end of the Bundesbank list
                    //they do some comments
                }

            }

        }
        private void ReadBundesbankLine(string strLine, ListQuotes qc)
        {
            if (strLine != null && strLine != string.Empty)
            {
                IQuote qu = new Quote();
                string[] listQuotes = strLine.Split(new Char[] { ';' });
                try
                {
                    qu.DATE = Convert.ToDateTime(listQuotes[0], CUtil.Conversions.CultureGerman);
                    string str = listQuotes[1];
                    if (SetQuoteFromGermanPublicYield(str, qu))
                    {
                        if (qu.DATE > dateStart)
                        {
                            qc.Add(qu);

                        }
                    }
                }
                catch
                {
                    // do nothing - probably conversion error - at the end of the Bundesbank list
                    //they do some comments
                }

            }

        }
        protected bool AdjustQuoteCollection(ListQuotes qc, IDataItem mydataItem)
        {
            this.dataItem = mydataItem;
            if (qc.Count > 1)
            {
                //put them in reverse order 
                ListQuotes qnew = new ListQuotes(dataItem.DataClass);
                for (int j = 0; j < qc.Count; j++)
                {
                    qnew.Add(qc[qc.Count - j - 1]);
                }
                System.Diagnostics.Debug.WriteLine("Number of quotes read: " + dataItem.DataClass.QuoteCollection.Count.ToString());

                dataItem.DataClass.QuoteCollection = qnew;
                dataItem.DataClass.Serialize();
            }
            return true;

        }


       
        private void GetStockData(string stockCode)
        {
            string serverUrl = @"http://in.finance.yahoo.com/d/quotes.csv?s=" + stockCode +
                    "&f=sl1d1t1c1ohgvj1pp2owern&e=.csv";

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serverUrl);

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            StreamReader reader = new StreamReader(response.GetResponseStream(),
                Encoding.ASCII);

            string stockDataString = reader.ReadLine();
            string[] stockDataContents = stockDataString.Split(',');

            //stockData.Code = stockCode;
            //stockData.Last = stockDataContents[1];
            //stockData.Date = stockDataContents[2];
            //stockData.Time = stockDataContents[3];
            //stockData.Change = stockDataContents[4];
            //stockData.Open = stockDataContents[5];
            //stockData.High = stockDataContents[6];
            //stockData.Low = stockDataContents[7];
            //stockData.Volume = stockDataContents[8];
            //stockData.MarketCapital = stockDataContents[9];
            //stockData.PreviousClose = stockDataContents[10];
            //stockData.PctChange = stockDataContents[11];
            //stockData.AnnRange = stockDataContents[12];
            //stockData.Earnings = stockDataContents[13];
            //stockData.PERatio = stockDataContents[14];

            response.Close();
        }

        //Depending on selected node - display latest data in list
        private void DisplayStockList()
        {


            //double todaysChange = 0;
            //double netChange = 0;
            //double totalInitial = 0;
            //double totalCurrent = 0;

            //double diff = Convert.ToDouble(stockData.Last) -
            //                Convert.ToDouble(stockData.PreviousClose);
            //double percentDiff = (diff * 100) / Convert.ToDouble(stockData.PreviousClose);

            //double netDiff = (Convert.ToDouble(stockData.Last) - stockData.BuyPrice) *
            //                stockData.BuyQuantity;
            //double percentNetDiff = (netDiff * 100) / (stockData.BuyPrice * stockData.BuyQuantity);

            //            todaysChange += diff * stockData.BuyQuantity;
            //            netChange += netDiff;
            //            totalInitial += stockData.BuyPrice * stockData.BuyQuantity;
            //            totalCurrent += Convert.ToDouble(stockData.Last) * stockData.BuyQuantity;






        }
    

        #endregion

    }
}